<template>
<div>
  <a-row :gutter="10">
    <a-col :md="leftColMd" :sm="24" style="margin-bottom: 20px">
      <a-card :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
            </a-row>
          </a-form>
        </div>
        <!-- 查询区域-END -->

        <!-- 操作按钮区域 -->
        <div class="table-operator">
          <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
          <a-button type="primary" icon="download" @click="handleExportXls('报名信息')">导出</a-button>
          <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
            <a-button type="primary" icon="import">导入</a-button>
          </a-upload>
          <!-- 高级查询区域 -->
          <j-super-query :fieldList="superFieldList" ref="superQueryModal" @handleSuperQuery="handleSuperQuery"></j-super-query>
          <a-dropdown v-if="selectedRowKeys1.length > 1">
            <a-menu slot="overlay">
              <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>删除</a-menu-item>
            </a-menu>
            <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
          </a-dropdown>
        </div>

        <!-- table区域-begin -->
        <div>
          <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
            <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys1.length }}</a>项
            <a style="margin-left: 24px" @click="onClearSelected1">清空</a>
          </div>

          <a-table
            ref="table"
            size="middle"
            :scroll="{x:true}"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :loading="loading"
            :rowSelection="{selectedRowKeys: selectedRowKeys1, onChange: onSelectChange1, type:'radio'}"
            
            class="j-table-force-nowrap"
            @change="handleTableChange">

            <a slot="project_dictText" slot-scope="text, record" @click="getProjectDetails(record.project)">{{ text }}</a>
            
            <span slot="action" slot-scope="text, record">
              <a @click="handleApartOpen(record)">部门</a>
              <a-divider type="vertical" />

              <a-popconfirm title="确定转分配后报名将立即停止，开始分配房源，确定吗?" @confirm="() => applyToDistribute(record)">
                <a>报名转分配</a>
              </a-popconfirm>

              <a-divider type="vertical" />
              <a @click="employeeApplyCheckInfo(record)">报名</a>

              <a-modal v-model="userApplyVisible" title="报名" ok-text="提交报名" cancel-text="取消" @ok="employeeApplySubmit">
                <p v-if="userApplyReminderModel.checkInfoResult && userApplyReminderModel.checkInfoResult.length > 0" style="color: #000">
                  {{userApplyReminderModel.checkInfoResult[0]}}
                </p>
                <p v-if="userApplyReminderModel.checkInfoResult && userApplyReminderModel.checkInfoResult.length > 1" style="color: #6495ED">
                  {{userApplyReminderModel.checkInfoResult[1]}}
                </p>
                <p v-if="userApplyReminderModel.checkInfoResult && userApplyReminderModel.checkInfoResult.length > 2" style="color: #FF7F50">
                  {{userApplyReminderModel.checkInfoResult[2]}}
                </p>
                <p v-if="userApplyReminderModel.checkInfoResult && userApplyReminderModel.checkInfoResult.length > 3" style="color: #FF7F50">
                  {{userApplyReminderModel.checkInfoResult[3]}}
                </p>
                <p v-if="userApplyReminderModel.checkInfoResult && userApplyReminderModel.checkInfoResult.length > 4" style="color: #FF7F50">
                  {{userApplyReminderModel.checkInfoResult[4]}}
                </p>
              </a-modal>

              <a-divider type="vertical" />
              <a-dropdown>
                <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                <a-menu slot="overlay">
                  <a-menu-item>
                    <a @click="handleEdit(record)">编辑</a>
                  </a-menu-item>
                  <a-menu-item>
                    <a @click="handleDetail(record)">详情</a>
                  </a-menu-item>
                  <a-menu-item>
                    <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete1(record.id)">
                      <a>删除</a>
                    </a-popconfirm>
                  </a-menu-item>
                </a-menu>
              </a-dropdown>
            </span>

          </a-table>
        </div>
        <projectInfoDrawer ref="projectDrawer"></projectInfoDrawer>
        <znzf-apply-modal ref="modalForm" @ok="modalFormOk"></znzf-apply-modal>
      </a-card>
    </a-col>

    <a-col :md="rightColMd" :sm="24" v-if="this.rightupcolval == 1" style="margin-bottom: 20px">
      
      <a-card :bordered="false">
      <!-- 按钮操作区域 -->
        <a-row style="margin-left: 14px">
          <a-button @click="handleAdd2(1)" type="primary">添加部门</a-button>
          <a-button @click="handleAdd2(2)" type="primary" style="margin-left: 8px">添加下级</a-button>
        </a-row>
        <div style="background: #fff;padding-left:16px;height: 100%; margin-top: 5px">
          <a-alert type="info" :showIcon="true">
            <div slot="message">
              当前选择：<span v-if="this.currSelected2.title">{{ getApartCurrSelectedTitle() }}</span>
              <a v-if="this.currSelected2.title" style="margin-left: 10px" @click="onClearSelected2">取消选择</a>
            </div>
          </a-alert>
          <a-input-search @search="onSearch2" style="width:100%;margin-top: 10px" placeholder="请输入部门名称"/>
          <!-- 树-->
          <a-col :md="10" :sm="24">
            <template>
              <a-dropdown :trigger="[this.dropTrigger]" @visibleChange="dropStatus">
              <span style="user-select: none">
            <a-tree
              checkable
              multiple
              @select="onSelect2"
              @check="onCheck2"
              @rightClick="rightHandle"
              :selectedKeys="selectedKeys2"
              :checkedKeys="checkedKeys"
              :treeData="departTree"
              :checkStrictly="checkStrictly"
              :expandedKeys="iExpandedKeys"
              :autoExpandParent="autoExpandParent"
              @expand="onExpand"/>
                </span>
                <!--新增右键点击事件,和增加添加和删除功能-->
                <a-menu slot="overlay">
                  <a-menu-item @click="handleAdd2(3)" key="1">添加</a-menu-item>
                  <a-menu-item @click="handleDelete2" key="2">删除</a-menu-item>
                  <a-menu-item @click="closeDrop" key="3">取消</a-menu-item>
                </a-menu>
              </a-dropdown>
            </template>
          </a-col>
        </div>
      </a-card>
      <!---- author:os_chengtgen -- date:20190827 --  for:切换父子勾选模式 =======------>
      <div class="drawer-bootom-button">
        <a-dropdown :trigger="['click']" placement="topCenter">
          <a-menu slot="overlay">
            <a-menu-item key="1" @click="switchCheckStrictly(1)">父子关联</a-menu-item>
            <a-menu-item key="2" @click="switchCheckStrictly(2)">取消关联</a-menu-item>
            <a-menu-item key="3" @click="checkALL">全部勾选</a-menu-item>
            <a-menu-item key="4" @click="cancelCheckALL">取消全选</a-menu-item>
            <a-menu-item key="5" @click="expandAll">展开所有</a-menu-item>
            <a-menu-item key="6" @click="closeAll">合并所有</a-menu-item>
          </a-menu>
          <a-button>
            树操作 <a-icon type="up" />
          </a-button>
        </a-dropdown>

        <a-button @click="updateDetermineApart()" style="float: right;margin-right: 15px " type="primary">更新部门</a-button>
      </div>
    </a-col>
    <depart-modal ref="departModal" @ok="loadTree"></depart-modal>
  </a-row>

  <a-row v-if="this.rightdowncolval == 1">
    <a-col :md="24" :sm="24" style="margin-bottom: 20px">
      <a-tabs defaultActiveKey="2">
        <a-tab-pane tab="基本信息" key="1" >
          <a-card :bordered="false" v-if="selectedKeys2.length>0">
            <a-form-model ref="form" :model="model" :rules="validatorRules">
              <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="departName" label="机构名称">
                <a-input placeholder="请输入机构/部门名称" v-model="model.departName" />
              </a-form-model-item>
              <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="上级部门">
                <a-tree-select
                  style="width:100%"
                  :dropdownStyle="{maxHeight:'200px',overflow:'auto'}"
                  :treeData="treeData"
                  :disabled="disable"
                  v-model="model.parentId"
                  placeholder="无">
                </a-tree-select>
              </a-form-model-item>
              <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orgCode" label="机构编码">
                <a-input disabled placeholder="请输入机构编码" v-model="model.orgCode" />
              </a-form-model-item>
              <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orgCategory" label="机构类型">
                <template v-if="orgCategoryDisabled">
                  <a-radio-group v-model="model.orgCategory" placeholder="请选择机构类型">
                    <a-radio value="1">
                      公司
                    </a-radio>
                  </a-radio-group>
                </template>
                <template v-else>
                  <a-radio-group v-model="model.orgCategory" placeholder="请选择机构类型">
                    <a-radio value="2">
                      部门
                    </a-radio>
                    <a-radio value="3">
                      岗位
                    </a-radio>
                  </a-radio-group>
                </template>
              </a-form-model-item>
              <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="排序">
                <a-input-number v-model="model.departOrder" />
              </a-form-model-item>
              <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="手机号">
                <a-input placeholder="请输入手机号" v-model="model.mobile" />
              </a-form-model-item>
              <a-form-model-item  :labelCol="labelCol" :wrapperCol="wrapperCol"  label="地址">
                <a-input placeholder="请输入地址" v-model="model.address"/>
              </a-form-model-item>
              <a-form-model-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="备注">
                <a-textarea placeholder="请输入备注" v-model="model.memo"/>
              </a-form-model-item>
            </a-form-model>
            <div class="anty-form-btn">
              <a-button @click="emptyCurrForm" type="default" htmlType="button" icon="sync">重置</a-button>
              <a-button @click="submitCurrForm" type="primary" htmlType="button" icon="form"
              style="margin-left: 8px">保存</a-button>
            </div>
          </a-card>
          <a-card v-else >
            <a-empty>
              <span slot="description"> 请先选择一个部门! </span>
            </a-empty>
          </a-card>
        </a-tab-pane>
        <a-tab-pane tab="报名职员" key="2" forceRender>
          
          <a-card :bordered="false">
            <!-- 查询区域 -->
            <div class="table-page-search-wrapper">
              <a-form layout="inline">
                <a-row :gutter="24">

                  <a-col :md="12" :sm="12">
                    <a-form-item label="职员姓名">
                      <a-input placeholder="" v-model="queryParam3.name"></a-input>
                    </a-form-item>
                  </a-col>
                  <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                  <a-col :md="9" :sm="24">
                    <a-button type="primary" @click="searchQuery3" icon="search" style="margin-left: 21px">查询</a-button>
                    <a-button type="primary" @click="searchReset3" icon="reload" style="margin-left: 8px">重置</a-button>
                    </a-col>
                  </span>
                </a-row>
              </a-form>
            </div>

            <!-- 操作按钮区域 -->
            <div class="table-operator">
              <a-dropdown v-if="selectedRowKeys3.length > 0">
                <a-menu slot="overlay">
                  <a-menu-item key="1" @click="batchDel3"><a-icon type="delete"/>删除</a-menu-item>
                </a-menu>
                <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>
              </a-dropdown>
            </div>

            <!-- table区域-begin -->
            <div>
              <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
                <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys3.length }}</a>项
                <a style="margin-left: 24px" @click="onClearSelected3">清空</a>
              </div>

              <a-table
                ref="table"
                size="middle"
                :scroll="{x:true}"
                bordered
                rowKey="id"
                :columns="columns3"
                :dataSource="dataSource3"
                :pagination="ipagination3"
                :loading="loading3"
                :rowSelection="{selectedRowKeys: selectedRowKeys3, onChange: onSelectChange3}"
                class="j-table-force-nowrap"
                @change="handleTableChange3">

                <span slot="action" slot-scope="text, record">
                  <a @click="shortListed(record)">入围</a>

                  <a-divider type="vertical" />
                  <a-dropdown>
                    <a class="ant-dropdown-link">更多 <a-icon type="down" /></a>
                    <a-menu slot="overlay">
                      <a-menu-item>
                        <a @click="handleDetail3(record)">详情</a>
                      </a-menu-item>
                      <a-menu-item>
                        <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete3(record.id)">
                          <a>删除</a>
                        </a-popconfirm>
                      </a-menu-item>
                    </a-menu>
                  </a-dropdown>
                </span>

              </a-table>
            </div>
            <znzf-apply-apart-employee-modal ref="modalForm3" @ok="modalFormOk3"></znzf-apply-apart-employee-modal>
          </a-card>

        </a-tab-pane>
      </a-tabs>
    </a-col>
  </a-row>
</div>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import ZnzfApplyModal from './modules/ZnzfApplyModal'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import DepartModal from '../system/modules/DepartModal'
  import {queryDepartTreeList, searchByKeywords, deleteByDepartId} from '@/api/api'
  import {httpAction, deleteAction, postAction, getAction} from '@/api/manage'
  import ZnzfApplyApartEmployeeModal from '../applyapartemployee/modules/ZnzfApplyApartEmployeeModal'
  import { filterObj } from '@/utils/util'
  import store from '@/store/'
  import projectInfoDrawer from '@/components/znzfComponents/projectInfoDrawer'
  

  export default {
    name: 'ZnzfApplyList',
    mixins:[JeecgListMixin, mixinDevice],
    components: {
      ZnzfApplyModal,
      DepartModal,
      ZnzfApplyApartEmployeeModal,
      projectInfoDrawer,
    },
    data () {
      return {
        description: '报名信息管理页面',

        userApplyVisible: false,
        userApplyReminderModel: {
          checkInfoResult: [],
          canApply: false,
          applyidx: '',
        },
        currentApplyId: '',

        selectedRowKeys1: [],
        selectionRows1: [],

        // 表头
        columns: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'标题',
            align:"center",
            dataIndex: 'title'
          },
          {
            title:'所属项目',
            align:"center",
            dataIndex: 'project_dictText',
            scopedSlots: { customRender: 'project_dictText' },
          },
          {
            title:'报名开始时间',
            align:"center",
            dataIndex: 'applyStartTime'
          },
          {
            title:'报名截止日期',
            align:"center",
            sorter: true,
            dataIndex: 'applyEndTime'
          },
          {
            title:'公示开始日期',
            align:"center",
            dataIndex: 'noticeStartTime'
          },
          {
            title:'公示截止日期',
            align:"center",
            sorter: true,
            dataIndex: 'noticeEndTime'
          },
          {
            title:'核查截止日期',
            align:"center",
            sorter: true,
            dataIndex: 'checkEndTime'
          },
          {
            title:'是否停止报名',
            align:"center",
            dataIndex: 'isStopApply_dictText'
          },
          {
            title:'是否停止核查',
            align:"center",
            dataIndex: 'isStopCheck_dictText'
          },
          {
            title:'是否完结',
            align:"center",
            dataIndex: 'isFinish_dictText'
          },
          {
            title:'当前阶段',
            align:"center",
            dataIndex: 'currentStatus_dictText'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:200,
            scopedSlots: { customRender: 'action' }
          }
        ],
        
        rightupcolval:0,
        iExpandedKeys: [],
        autoExpandParent: true,
        disable: true,
        treeData: [],
        visible: false,
        departTree: [],
        rightClickSelectedKey2: '',
        rightClickSelectedOrgCode: '',
        model: {},
        dropTrigger: '',
        depart: {},
        columns2: [
          {
            title: '机构名称',
            dataIndex: 'departName'
          },
          {
            title: '机构类型',
            align: 'center',
            dataIndex: 'orgType'
          },
          {
            title: '机构编码',
            dataIndex: 'orgCode',
          },
          {
            title: '手机号',
            dataIndex: 'mobile'
          },
          {
            title: '传真',
            dataIndex: 'fax'
          },
          {
            title: '地址',
            dataIndex: 'address'
          },
          {
            title: '排序',
            align: 'center',
            dataIndex: 'departOrder'
          },
          {
            title: '操作',
            align: 'center',
            dataIndex: 'action',
            scopedSlots: {customRender: 'action'}
          }
        ],
        disableSubmit: false,
        checkedKeys: [],
        selectedKeys2: [],
        autoIncr: 1,
        currSelected2: {},
        allTreeKeys:[],
        checkStrictly: true,
        labelCol: {
          xs: {span: 24},
          sm: {span: 5}
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 16}
        },
        graphDatasource: {
          nodes: [],
          edges: []
        },
        validatorRules: {
          departName: [{required: true, message: '请输入机构/部门名称!'}],
          orgCode: [{required: true, message: '请输入机构编码!'}],
          orgCategory:[{required: true, message: '请输入机构类型!'}],
          mobile:[{validator: this.validateMobile}]
        },
        orgCategoryDisabled:false,



        rightdowncolval:0,
        queryParam3: {},
        dataSource3: [],
        loading3: false,
        filters3: {},
        selectedRowKeys3: [],
        selectionRows3: [],
        isorter3: {
          column: 'createTime',
          order: 'desc'
        },
        ipagination3: {
          current: 1,
          pageSize: 10,
          pageSizeOptions: ['10', '20', '30'],
          showTotal: (total, range) => {
            return range[0] + '-' + range[1] + ' 共' + total + '条'
          },
          showQuickJumper: true,
          showSizeChanger: true,
          total: 0
        },
        columns3: [
          {
            title: '#',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'职员姓名',
            align:"center",
            dataIndex: 'name'
          },
          {
            title:'手机号',
            align:"center",
            dataIndex: 'tel'
          },
          {
            title:'报名时间',
            align:"center",
            sorter: true,
            dataIndex: 'applyTime'
          },
          {
            title:'得分',
            align:"center",
            sorter: true,
            dataIndex: 'score'
          },
          {
            title:'排名',
            align:"center",
            dataIndex: 'rank'
          },
          {
            title:'是否入围',
            align:"center",
            dataIndex: 'isShortlisted_dictText'
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:147,
            scopedSlots: { customRender: 'action' }
          }
        ],

        url: {
          list: "/applyinfo/znzfApply/list",
          
          delete: "/applyinfo/znzfApply/delete",
          deleteBatch: "/applyinfo/znzfApply/deleteBatch",
          exportXlsUrl: "/applyinfo/znzfApply/exportXls",
          importExcelUrl: "applyinfo/znzfApply/importExcel",

          list2: "/applyinfo/znzfDetermineApart/queryDeparts",
          edit2: "/sys/sysDepart/edit",
          updateapartofapply: "/applyinfo/znzfDetermineApart/updateDeparts",

          deleteBatch3: '/applyapartemployee/znzfApplyApartEmployee/deleteBatch',
          delete3: '/applyapartemployee/znzfApplyApartEmployee/delete',
          list3: '/applyapartemployee/znzfApplyApartEmployee/queryByApplyListIdAndApartId',
          shortlisted: '/applyapartemployee/znzfApplyApartEmployee/shortlist',

          applyCheckInfo: '/applyinfo/znzfApply/checkapplyinfo',
          employeeApplySubmit: '/applyapartemployee/znzfApplyApartEmployee/submitapply',

          applyToDistribute: '/roomapartdistribute/znzfRoomApartDistribute/znzfApplyToZnzfRoomApartDistribute',
        },


        dictOptions:{},
        superFieldList:[],
      }
    },
    created() {
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
      leftColMd() {
        return this.selectedRowKeys1.length === 0 ? 24 : 12
      },
      rightColMd() {
        return this.selectedRowKeys1.length === 0 ? 0 : 12
      },

    },
    methods: {
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'title',text:'标题',dictCode:''})
        fieldList.push({type:'sel_search',value:'project',text:'所属项目',dictTable:"znzf_project", dictText:'name', dictCode:'id'})
        fieldList.push({type:'string',value:'checkPeopleId',text:'当前处理人id',dictCode:''})
        fieldList.push({type:'datetime',value:'applyEndTime',text:'报名截止日期'})
        fieldList.push({type:'datetime',value:'noticeEndTime',text:'公示截止日期'})
        fieldList.push({type:'datetime',value:'checkEndTime',text:'核查截止日期'})
        fieldList.push({type:'int',value:'isStopApply',text:'是否停止报名',dictCode:'yn'})
        fieldList.push({type:'int',value:'isStopCheck',text:'是否停止核查',dictCode:'yn'})
        fieldList.push({type:'int',value:'isFinish',text:'是否完结',dictCode:'yn'})
        fieldList.push({type:'string',value:'currentStatus',text:'当前阶段',dictCode:'apply_status'})
        this.superFieldList = fieldList
      },
      getProjectDetails(projectId){
        this.$refs.projectDrawer.showProjectInfo(projectId);
      },
      handleDelete1: function(id) {
        if(this.currentApplyId === id){
          this.rightdowncolval = 0
          this.checkedKeys = []
          this.selectedKeys2 = []
          this.currSelected2 = {}
          this.dataSource3 = []
          this.rightupcolval = 0
        }
        this.handleDelete(id)
      },
      onClearSelected1() {
        this.selectedRowKeys1 = []
        this.selectionRows1 = []
        this.rightdowncolval = 0
        this.checkedKeys = []
        this.selectedKeys2 = []
        this.currSelected2 = {}
        this.rightupcolval = 0
      },
      onSelectChange1(selectedRowKeys, selectionRows) {
        this.rightupcolval = 1
        this.selectedRowKeys1 = selectedRowKeys
        this.selectionRows1 = selectionRows
        this.currentApplyId = selectedRowKeys[0]
        this.loadTree()
        this.loadData2()
      },
      handleApartOpen(record) {
        this.rightupcolval = 1
        this.selectedRowKeys1 = [record.id]
        this.currentApplyId = record.id
        this.loadTree()
        this.loadData2()
      },
      applyToDistribute(record) {
        if (!this.url.applyToDistribute) {
          this.$message.error('请设置url.applyToDistribute属性!')
          return
        }

        if (record.id === '') return
        let params ={
          applyId: record.id,
        }
        postAction(this.url.applyToDistribute, params).then((res) => {
          if (res.success) {
            
            this.onClearSelected1();
            this.loadData();
            this.$message.success('已结束报名，开始分配。')
          }
          else{
            this.$message.warning(res.message)
          }
        })
      },
      loadData2(){
        if (!this.url.list2) {
          this.$message.error('请设置url.list2属性!')
          return
        }

        if (this.currentApplyId === '') return
        let params ={
          applyId: this.currentApplyId,
        }
        getAction(this.url.list2, params).then((res) => {
          if (res.success) {
            this.checkedKeys = res.result;
          }
          else{
            this.$message.warning(res.message)
          }
        })
      },
      handleAdd2(num) {
        if (num == 1) {
          this.$refs.departModal.add()
          this.$refs.departModal.title = '新增'
        } else if (num == 2) {
          let key = this.currSelected2.key
          if (!key) {
            this.$message.warning('请先点击选中上级部门！')
            return false
          }
          this.$refs.departModal.add(this.selectedKeys2)
          this.$refs.departModal.title = '新增'
        } else {
          this.$refs.departModal.add(this.rightClickSelectedKey2)
          this.$refs.departModal.title = '新增'
        }
      },
      getApartCurrSelectedTitle(){
        return !this.currSelected2.title ? '' : this.currSelected2.title
      },
      onSearch2(value) {
        let that = this
        if (value) {
          searchByKeywords({keyWord: value}).then((res) => {
            if (res.success) {
              that.departTree = []
              for (let i = 0; i < res.result.length; i++) {
                let temp = res.result[i]
                that.departTree.push(temp)
              }
            } else {
              that.$message.warning(res.message)
            }
          })
        } else {
          that.loadTree()
        }
      },
      loadTree() {
        var that = this
        that.treeData = []
        that.departTree = []
        queryDepartTreeList().then((res) => {
          if (res.success) {
            //部门全选后，再添加部门，选中数量增多
            this.allTreeKeys = [];
            for (let i = 0; i < res.result.length; i++) {
              let temp = res.result[i]
              that.treeData.push(temp)
              that.departTree.push(temp)
              that.setThisExpandedKeys(temp)
              that.getAllKeys(temp);
              // console.log(temp.id)
            }
          }
        })
      },
      setThisExpandedKeys(node) {
        if (node.children && node.children.length > 0) {
          this.iExpandedKeys.push(node.key)
          for (let a = 0; a < node.children.length; a++) {
            this.setThisExpandedKeys(node.children[a])
          }
        }
      },
      // 右键操作方法
      rightHandle(node) {
        this.dropTrigger = 'contextmenu'
        console.log(node.node.eventKey)
        this.rightClickSelectedKey2 = node.node.eventKey
        this.rightClickSelectedOrgCode = node.node.dataRef.orgCode
      },
      onExpand(expandedKeys) {
        console.log('onExpand', expandedKeys)
        this.iExpandedKeys = expandedKeys
        this.autoExpandParent = false
      },
      // 右键点击下拉框改变事件
      dropStatus(visible) {
        if (visible == false) {
          this.dropTrigger = ''
        }
      },
      // 右键下拉关闭下拉框
      closeDrop() {
        this.dropTrigger = ''
      },
      onCheck2(checkedKeys, info) {
        console.log('onCheck', checkedKeys, info)
        //---- author:os_chengtgen -- date:20190827 --  for:切换父子勾选模式 =======------
        if(this.checkStrictly){
          this.checkedKeys = checkedKeys.checked;
        }else{
          this.checkedKeys = checkedKeys
        }
        //---- author:os_chengtgen -- date:20190827 --  for:切换父子勾选模式 =======------
      },
      onSelect2(selectedKeys, e) {
        this.rightdowncolval = 1;

        console.log('selected', selectedKeys, e)
        let record = e.node.dataRef
        console.log('onSelect-record', record)
        this.currSelected2 = Object.assign({}, record)
        this.model = this.currSelected2
        this.selectedKeys2 = [record.key]

        this.model.parentId = record.parentId
        this.setValuesToForm(record)

        //加载报名人员数据
        this.loadData3()

      },
      // 触发onSelect事件时,为部门树右侧的form表单赋值
      setValuesToForm(record) {
        if(record.orgCategory == '1'){
          this.orgCategoryDisabled = true;
        }else{
          this.orgCategoryDisabled = false;
        }
      },
      
      onClearSelected2() {
        this.currSelected2 = {}
        this.selectedKeys2 = []

        this.rightdowncolval = 0;
        //报名人员数据清空
        this.dataSource3 = []
        this.ipagination3.total = 0
        this.rightdowncolval = 0
      },
      handleNodeTypeChange(val) {
        this.currSelected2.nodeType = val
      },
      notifyTriggerTypeChange(value) {
        this.currSelected2.notifyTriggerType = value
      },
      receiptTriggerTypeChange(value) {
        this.currSelected2.receiptTriggerType = value
      },
      submitCurrForm() {
        this.$refs.form.validate(valid => {
          if (valid) {
            if (!this.currSelected2.id) {
              this.$message.warning('请点击选择要修改部门!')
              return
            }

            httpAction(this.url.edit2, this.currSelected2, 'put').then((res) => {
              if (res.success) {
                this.$message.success('保存成功!')
                this.loadTree()
              } else {
                this.$message.error(res.message)
              }
            })
          }
        })
      },
      emptyCurrForm() {
        this.$refs.form.resetFields();
        this.model={}
      },
      nodeSettingFormSubmit() {
        this.$refs.form.validate(valid => {
          if (valid) {
            console.log('Received values of form: ', this.model)
          }
        })
      },
      handleDelete2() {
        var that = this
        this.$confirm({
          title: '确认删除',
          content: '确定要删除此部门以及子节点数据吗?',
          onOk: function () {
            deleteByDepartId({id: that.rightClickSelectedKey2}).then((resp) => {
              if (resp.success) {
                //删除成功后，去除已选中中的数据
                that.checkedKeys.splice(that.checkedKeys.findIndex(key => key === that.rightClickSelectedKey2), 1);
                that.$message.success('删除成功!')
                that.loadTree()
                //删除后同步清空右侧基本信息内容
                let orgCode=that.model.orgCode;
                if(orgCode && orgCode === that.rightClickSelectedOrgCode){
                  that.onClearSelected2()
                }
              } else {
                that.$message.warning('删除失败!')
              }
            })
          }
        })
      },
      selectDirectiveOk(record) {
        console.log('选中指令数据', record)
        this.nodeSettingForm.setFieldsValue({directiveCode: record.directiveCode})
        this.currSelected2.sysCode = record.sysCode
      },
      getFlowGraphData(node) {
        this.graphDatasource.nodes.push({
          id: node.id,
          text: node.flowNodeName
        })
        if (node.children.length > 0) {
          for (let a = 0; a < node.children.length; a++) {
            let temp = node.children[a]
            this.graphDatasource.edges.push({
              source: node.id,
              target: temp.id
            })
            this.getFlowGraphData(temp)
          }
        }
      },
     //---- author:os_chengtgen -- date:20190827 --  for:切换父子勾选模式 =======------
      expandAll () {
        this.iExpandedKeys = this.allTreeKeys
      },
      closeAll () {
        this.iExpandedKeys = []
      },
      checkALL () {
        this.checkStriccheckStrictlytly = false
        this.checkedKeys = this.allTreeKeys
      },
      cancelCheckALL () {
        //this.checkedKeys = this.defaultCheckedKeys
        this.checkedKeys = []
      },
      switchCheckStrictly (v) {
        if(v==1){
          this.checkStrictly = false
        }else if(v==2){
          this.checkStrictly = true
        }
      },
      getAllKeys(node) {
        // console.log('node',node);
        this.allTreeKeys.push(node.key)
        if (node.children && node.children.length > 0) {
          for (let a = 0; a < node.children.length; a++) {
            this.getAllKeys(node.children[a])
          }
        }
      },
      //---- author:os_chengtgen -- date:20190827 --  for:切换父子勾选模式 =======------
      
      updateDetermineApart(){
        if (!this.url.updateapartofapply) {
          this.$message.error('请设置url.updateapartofapply!')
          return
        }

        if (this.currentApplyId === '') return
        let params = {
          applyId: this.currentApplyId,
          departIds: this.checkedKeys,
        }
        postAction(this.url.updateapartofapply, params).then((res) => {
          if (res.success) {
            this.$message.success('更新成功!')
            this.loadData2();
          }
        })
      },


      getQueryParams3() {
        //获取查询条件
        let sqp = {}
        var param = Object.assign(sqp, this.queryParam3, this.isorter3 ,this.filters3);
        param.field = this.getQueryField3();
        param.pageNo = this.ipagination3.current;
        param.pageSize = this.ipagination3.pageSize;
        return filterObj(param);
      },
      getQueryField3() {
        //TODO 字段权限控制
        var str = "id,";
        this.columns3.forEach(function (value) {
          str += "," + value.dataIndex;
        });
        return str;
      },

      loadData3(arg) {
        if (!this.url.list3) {
          this.$message.error('请设置url.list3属性!')
          return
        }
        //加载数据 若传入参数1则加载第一页的内容
        if (arg === 1) {
          this.ipagination3.current = 1
        }
        if (this.currentApplyId === '' || this.selectedKeys2.length <= 0 || this.selectedKeys2[0] === '') return
        
        let params = this.getQueryParams3()//查询条件
        params.applyId = this.currentApplyId
        params.apartId = this.selectedKeys2[0]

        this.loading3 = true

        getAction(this.url.list3, params).then((res) => {
          if (res.success) {
            this.dataSource3 = res.result.records;
            if(res.result.total)
            {
              this.ipagination3.total = res.result.total;
            }else{
              this.ipagination3.total = 0;
            }
          }else{
            this.dataSource3 = [];
            this.ipagination3.total = 0;
            this.$message.warning(res.message)
          }
        }).finally(() => {
          this.loading3 = false
        })
      },
      searchQuery3() {
        this.loadData3(1)
      },
      searchReset3() {
        this.queryParam3 = {}
        this.loadData3(1)
      },
      batchDel3: function () {
        if(!this.url.deleteBatch3){
          this.$message.error("请设置url.deleteBatch3属性!")
          return
        }
        if (this.selectedRowKeys3.length <= 0) {
          this.$message.warning('请选择一条记录！');
          return;
        } else {
          var ids = "";
          for (var a = 0; a < this.selectedRowKeys3.length; a++) {
            ids += this.selectedRowKeys3[a] + ",";
          }
          var that = this;
          this.$confirm({
            title: "确认删除",
            content: "是否删除选中数据?",
            onOk: function () {
              that.loading3 = true;
              deleteAction(that.url.deleteBatch3, {ids: ids}).then((res) => {
                if (res.success) {
                  //重新计算分页问题
                  that.reCalculatePage3(that.selectedRowKeys3.length)
                  that.$message.success(res.message);
                  that.loadData3();
                  that.onClearSelected3();
                } else {
                  that.$message.warning(res.message);
                }
              }).finally(() => {
                that.loading3 = false;
              });
            }
          });
        }
      },
      onSelectChange3(selectedRowKeys, selectionRows) {
        this.selectedRowKeys3 = selectedRowKeys
        this.selectionRows3 = selectionRows
      },
      onClearSelected3(){
        this.selectedRowKeys3 = []
        this.selectionRows3 = []
      },
      handleTableChange3(pagination, filters, sorter) {
        //分页、排序、筛选变化时触发
        //TODO 筛选
        if (Object.keys(sorter).length > 0) {
          this.isorter3.column = sorter.field
          this.isorter3.order = 'ascend' == sorter.order ? 'asc' : 'desc'
        }
        this.ipagination3 = pagination
        this.loadData3()
      },
      handleDetail3:function(record){
        this.$refs.modalForm3.edit(record);
        this.$refs.modalForm3.title="详情";
        this.$refs.modalForm3.disableSubmit = true;
      },
      handleDelete3: function (id) {
        if(!this.url.delete3){
          this.$message.error("请设置url.delete3属性!")
          return
        }
        var that = this;
        deleteAction(that.url.delete3, {id: id}).then((res) => {
          if (res.success) {
            //重新计算分页问题
            that.reCalculatePage3(1)
            that.$message.success(res.message);
            that.loadData3();
          } else {
            that.$message.warning(res.message);
          }
        });
      },
      reCalculatePage3(count){
        //总数量-count
        let total=this.ipagination3.total-count;
        //获取删除后的分页数
        let currentIndex=Math.ceil(total/this.ipagination3.pageSize);
        //删除后的分页数<所在当前页
        if(currentIndex<this.ipagination3.current){
          this.ipagination3.current=currentIndex;
        }
        console.log('currentIndex',currentIndex)
      },
      modalFormOk3(){
        this.loadData3()
      },
      shortListed(record){
        //入围
        if (!this.url.shortlisted) {
          this.$message.error('请设置url.shortlisted!')
          return
        }
        let params = {id: record.id};
        postAction(this.url.shortlisted, params).then((res) => {
          if (res.success) {
            this.$message.success('更新成功!')
            this.loadData3();
          }
          else{
            this.$message.warning(res.message);
          }
        })
      },

      //用户接口：
      //报名核对信息跳窗口
      employeeApplyCheckInfo(record){
        if (!this.url.applyCheckInfo) {
          this.$message.error('请设置url.applyCheckInfo!')
          return
        }
        this.userApplyReminderModel = {
          checkInfoResult: [],
          canApply: false,
          applyidx: record.id,
        };
        getAction(`${this.url.applyCheckInfo}/${record.id}`).then((res) => {
          if (res.success) {
            this.userApplyVisible = true;
            this.userApplyReminderModel.checkInfoResult = res.result.message.split("&");
            this.userApplyReminderModel.canApply = res.result.canApply;
          }
          else{
            this.$message.warning(res.message);
          }
        })
      },
      //提交报名
      employeeApplySubmit(){
        if(!this.userApplyReminderModel.canApply){
          this.$message.warning('您当前不符合报名条件！');
          return;
        }
        if(!this.userApplyReminderModel.applyidx){
          this.$message.error('提交错误！')
          return;
        }
        if (!this.url.employeeApplySubmit) {
          this.$message.error('请设置url.employeeApplySubmit!')
          return
        }
        let params ={id: this.userApplyReminderModel.applyidx}
        postAction(this.url.employeeApplySubmit, params).then((res) => {
          if (res.success) {
            this.$message.success('报名成功!')
            this.userApplyVisible = false;
          }
          else{
            this.$message.warning(res.message);
          }
        })
      },

    },

  }
</script>
<style scoped>
  @import '~@assets/less/common.less';

  .drawer-bootom-button {
    /*position: absolute;*/
    bottom: 0;
    width: 100%;
    border-top: 1px solid #e8e8e8;
    padding: 10px 16px;
    text-align: left;
    left: 0;
    background: #fff;
    border-radius: 0 0 2px 2px;
  }

</style>
